//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.fwt.*;
import fan.gfx.Color;
import fan.gfx.Font;
import fan.sys.*;
import org.eclipse.swtchart.IAxisTick;

public class AxisTickPeer {
  private IAxisTick _axisTick = null;

  public static AxisTickPeer make (fan.swtChartWrapper.AxisTick self) throws Exception {
    return new AxisTickPeer ();
  }

  public void setIAxisTick (IAxisTick axisTick) {
    _axisTick = axisTick;
    _axisTick.setFont (Fwt.get().font (_font));
    _axisTick.setForeground (Fwt.get().color (_foreground));
    _axisTick.setVisible (_visible);
    _axisTick.setTickLabelAngle ((int)_tickLabelAngle);
    _axisTick.setTickMarkStepHint ((int)_tickMarkStepHint);
  }

  private Font _font = Desktop.sysFont().toSize (9);
  public Font font (fan.swtChartWrapper.AxisTick self) { return _font; }
  public void font (fan.swtChartWrapper.AxisTick self, Font f) {
    _font = f;
    if (_axisTick != null) _axisTick.setFont (Fwt.get().font (_font));
  }

  private Color _foreground = Color.black;
  public Color foreground (fan.swtChartWrapper.AxisTick self) { return _foreground; }
  public void foreground (fan.swtChartWrapper.AxisTick self, Color v) {
    _foreground = v;
    if (_axisTick != null) _axisTick.setForeground (Fwt.get().color (_foreground));
  }
  
  private boolean _visible = true;
  public boolean visible (fan.swtChartWrapper.AxisTick self) { return _visible; }
  public void visible (fan.swtChartWrapper.AxisTick self, boolean v) {
    _visible = v;
    if (_axisTick != null) _axisTick.setVisible (_visible);
  }
  
  private long _tickLabelAngle = 0;
  public long labelAngle (fan.swtChartWrapper.AxisTick self) { return _tickLabelAngle; }
  public void labelAngle (fan.swtChartWrapper.AxisTick self, long v) {
    if (_tickLabelAngle <= 0) // trap negative angles
      _tickLabelAngle = 0;
    else if (_tickLabelAngle >= 90)  // trap large angles
      _tickLabelAngle = 90;
    else
      _tickLabelAngle = v;
    if (_axisTick != null) _axisTick.setTickLabelAngle ((int)_tickLabelAngle);
  }
  
  private long _tickMarkStepHint = 0;
  public long stepHint (fan.swtChartWrapper.AxisTick self) { return _tickMarkStepHint; }
  public void stepHint (fan.swtChartWrapper.AxisTick self, long v) {
    if (v < 0)  // trap negative values
      _tickMarkStepHint = 0;
    else
      _tickMarkStepHint = v;
    if (_axisTick != null) _axisTick.setTickMarkStepHint ((int)_tickMarkStepHint);
  }
}
